package com.chainshop.expenditure.service.impl;

import java.util.List;

import com.chainshop.common.core.domain.pojo.ExpenseRecords;
import com.chainshop.common.core.domain.pojo.ExpenseRequests;
import com.chainshop.common.core.domain.pojo.StoreInfo;
import com.chainshop.common.utils.SecurityUtils;
import com.chainshop.expenditure.mapper.ExpenseRecordsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.chainshop.expenditure.service.IExpenseRecordsService;

/**
 * 支出列表Service业务层处理
 * 
 * @author hmy
 * @date 2024-08-14
 */
@Service
public class ExpenseRecordsServiceImpl implements IExpenseRecordsService 
{
    @Autowired
    private ExpenseRecordsMapper expenseRecordsMapper;

    /**
     * 查询支出列表
     * 
     * @param id 支出列表主键
     * @return 支出列表
     */
    @Override
    public ExpenseRecords selectExpenseRecordsById(Long id)
    {
        return expenseRecordsMapper.selectExpenseRecordsById(id);
    }

    /**
     * 查询支出列表列表
     * 
     * @param expenseRecords 支出列表
     * @return 支出列表
     */
    @Override
    public List<ExpenseRecords> selectExpenseRecordsList(ExpenseRecords expenseRecords)
    {
        return expenseRecordsMapper.selectExpenseRecordsList(expenseRecords);
    }

    /**
     * 新增支出列表
     * 
     * @param expenseRecords 支出列表
     * @return 结果
     */
    @Override
    public int insertExpenseRecords(ExpenseRecords expenseRecords)
    {
        Long userId = SecurityUtils.getUserId();
        StoreInfo storeInfo = expenseRecordsMapper.selectStroeByUserId(userId);
        expenseRecords.setStoreId(storeInfo.getId());
        return expenseRecordsMapper.insertExpenseRecords(expenseRecords);
    }

    /**
     * 修改支出列表
     * 
     * @param expenseRecords 支出列表
     * @return 结果
     */
    @Override
    public int updateExpenseRecords(ExpenseRecords expenseRecords)
    {
        return expenseRecordsMapper.updateExpenseRecords(expenseRecords);
    }

    /**
     * 批量删除支出列表
     * 
     * @param ids 需要删除的支出列表主键
     * @return 结果
     */
    @Override
    public int deleteExpenseRecordsByIds(Long[] ids)
    {
        return expenseRecordsMapper.deleteExpenseRecordsByIds(ids);
    }

    /**
     * 删除支出列表信息
     * 
     * @param id 支出列表主键
     * @return 结果
     */
    @Override
    public int deleteExpenseRecordsById(Long id)
    {
        return expenseRecordsMapper.deleteExpenseRecordsById(id);
    }

    @Override
    public void insertByExpenseRequest(ExpenseRequests expenseRequests1) {
        ExpenseRecords expenseRecords = new ExpenseRecords();
        expenseRecords.setAmount(expenseRequests1.getExpenditureAmount());
        expenseRecords.setStoreId(expenseRequests1.getStoreId());
        expenseRecords.setApplicationId(expenseRequests1.getId());
        expenseRecords.setExpenditureType(expenseRequests1.getExpenditureType());
        expenseRecords.setExpenditureDate(expenseRequests1.getApplyDate());

        int i = insertExpenseRecords(expenseRecords);
    }
}
